#[==[.md
# smtk-config.cmake

This file is used by CMake when finding SMTK.

The following variables are provided by this module:

  * `smtk_PREFIX_PATH`: Install prefix for SMTK.
  * `smtk_VERSION`: The version of SMTK found.
  * `SMTK_OPERATION_INCLUDE_DIR`: The location under the install prefix for
    operation XML files.
  * `SMTK_ENABLE_PARAVIEW_SUPPORT`: Whether ParaView support is available or
    not.
  * `SMTK_ENABLE_PYTHON_WRAPPING`: Whether Python wrapping is available or not.
  * `SMTK_PYTHONPATH`: The path to smtk python.
  * `SMTK_ENABLE_QT_SUPPORT`: Whether Qt support is available or not.
  * `SMTK_ENABLE_REMUS_SUPPORT`: Whether Remus support is available or not.
  * `SMTK_ENABLE_VTK_SUPPORT`: Whether VTK support is available or not.
#]==]

set(${CMAKE_FIND_PACKAGE_NAME}_CMAKE_PREFIX_PATH_save "${CMAKE_PREFIX_PATH}")
include("${CMAKE_CURRENT_LIST_DIR}/smtk-prefix.cmake")
set("${CMAKE_FIND_PACKAGE_NAME}_PREFIX_PATH" "${_smtk_import_prefix}")
unset(_smtk_import_prefix)
list(INSERT CMAKE_PREFIX_PATH 0
  ${${CMAKE_FIND_PACKAGE_NAME}_PREFIX_PATH})

set("${CMAKE_FIND_PACKAGE_NAME}_VERSION" "@SMTK_VERSION@")

unset("${CMAKE_FIND_PACKAGE_NAME}_FOUND")

include("${CMAKE_CURRENT_LIST_DIR}/SMTKMacros.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/SMTKOperationXML.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/SMTKPluginMacros.cmake")

include("${CMAKE_CURRENT_LIST_DIR}/${CMAKE_FIND_PACKAGE_NAME}Targets.cmake")

set(SMTK_OPERATION_INCLUDE_DIR "@CMAKE_INSTALL_INCLUDEDIR@/smtk/@SMTK_VERSION@")
set(SMTK_ENABLE_PARAVIEW_SUPPORT "@SMTK_ENABLE_PARAVIEW_SUPPORT@")
set(SMTK_ENABLE_PYTHON_WRAPPING "@SMTK_ENABLE_PYTHON_WRAPPING@")
set(SMTK_ENABLE_QT_SUPPORT "@SMTK_ENABLE_QT_SUPPORT@")
set(SMTK_ENABLE_REMUS_SUPPORT "@SMTK_ENABLE_REMUS_SUPPORT@")
set(SMTK_ENABLE_VTK_SUPPORT "@SMTK_ENABLE_VTK_SUPPORT@")

include("${CMAKE_CURRENT_LIST_DIR}/smtk-find-package-helpers.cmake" OPTIONAL)

set(_smtk_find_quietly)
if (${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
  set(_smtk_find_quietly QUIET)
endif ()

# Required dependencies.

# Delaunay is always embedded.
set(Delaunay_DIR "${CMAKE_CURRENT_LIST_DIR}/Delaunay")
find_package(Delaunay REQUIRED ${_smtk_find_quietly})

find_package(Boost
  EXACT "@Boost_MAJOR_VERSION@.@Boost_MINOR_VERSION@.@Boost_SUBMINOR_VERSION@"
  ${_smtk_find_quietly}
  COMPONENTS
    @required_boost_components@)
if (NOT Boost_FOUND)
  list(APPEND "${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE"
    "Boost dependency not found")
  set("${CMAKE_FIND_PACKAGE_NAME}_FOUND" 0)
endif ()

find_package(LibArchive ${_smtk_find_quietly})
if (NOT LibArchive_FOUND)
  list(APPEND "${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE"
    "LibArchive dependency not found")
  set("${CMAKE_FIND_PACKAGE_NAME}_FOUND" 0)
endif ()

find_package(nlohmann_json ${_smtk_find_quietly})
if (NOT nlohmann_json_FOUND)
  list(APPEND "${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE"
    "nlohmann_json dependency not found")
  set("${CMAKE_FIND_PACKAGE_NAME}_FOUND" 0)
endif ()

find_package(pegtl ${_smtk_find_quietly})
if (NOT pegtl_FOUND)
  list(APPEND "${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE"
    "pegtl dependency not found")
  set("${CMAKE_FIND_PACKAGE_NAME}_FOUND" 0)
endif ()

find_package(MOAB ${_smtk_find_quietly})
if (NOT MOAB_FOUND)
  list(APPEND "${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE"
    "MOAB dependency not found")
  set("${CMAKE_FIND_PACKAGE_NAME}_FOUND" 0)
endif ()

find_package(Threads ${_smtk_find_quietly})
if (NOT Threads_FOUND)
  list(APPEND "${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE"
    "Threads dependency not found")
  set("${CMAKE_FIND_PACKAGE_NAME}_FOUND" 0)
endif()

if (SMTK_ENABLE_QT_SUPPORT)
  find_package(Qt5 ${_smtk_find_quietly}
    COMPONENTS Core OpenGL Widgets)
  if (NOT Qt5_FOUND)
    list(APPEND "${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE"
      "Qt5 dependency not found")
    set("${CMAKE_FIND_PACKAGE_NAME}_FOUND" 0)
  endif ()
endif ()

# ParaView is found first; if we have it, it will be finding VTK for us.
if (SMTK_ENABLE_PARAVIEW_SUPPORT)
  find_package(ParaView ${_smtk_find_quietly})
  if (NOT ParaView_FOUND)
    list(APPEND "${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE"
      "ParaView dependency not found")
    set("${CMAKE_FIND_PACKAGE_NAME}_FOUND" 0)
  endif ()
endif ()

if (SMTK_ENABLE_VTK_SUPPORT)
  # ParaView finds VTK for us.
  if (NOT SMTK_ENABLE_PARAVIEW_SUPPORT)
    find_package(VTK ${_smtk_find_quietly})
    if (NOT VTK_FOUND)
      list(APPEND "${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE"
        "VTK dependency not found")
      set("${CMAKE_FIND_PACKAGE_NAME}_FOUND" 0)
    endif ()
  endif ()

  include("${CMAKE_CURRENT_LIST_DIR}/SMTKVTKModules-targets.cmake")
  include("${CMAKE_CURRENT_LIST_DIR}/SMTKVTKModules-vtk-module-properties.cmake")

  if (@SMTK_ENABLE_VTK_SESSION@) # SMTK_ENABLE_VTK_SESSION
    include("${CMAKE_CURRENT_LIST_DIR}/SMTKVTKSession-targets.cmake")
  endif ()

  if (@SMTK_ENABLE_PARAVIEW_SUPPORT@) # SMTK_ENABLE_PARAVIEW_SUPPORT
    include("${CMAKE_CURRENT_LIST_DIR}/SMTKParaViewVTKModules-targets.cmake")
    include("${CMAKE_CURRENT_LIST_DIR}/SMTKParaViewVTKModules-vtk-module-properties.cmake")
  endif ()

  if (@SMTK_ENABLE_POLYGON_SESSION@) # SMTK_ENABLE_POLYGON_SESSION
    include("${CMAKE_CURRENT_LIST_DIR}/SMTKPolygonExt-targets.cmake")
    include("${CMAKE_CURRENT_LIST_DIR}/SMTKPolygonExt-vtk-module-properties.cmake")
  endif ()

endif ()

# Now include the ParaView-specific targets and information.
if (SMTK_ENABLE_PARAVIEW_SUPPORT)
  include("${CMAKE_CURRENT_LIST_DIR}/SMTKParaViewExtensionPlugins-smtk_paraview_extension_plugin-targets-depends.cmake")
  include("${CMAKE_CURRENT_LIST_DIR}/SMTKParaViewExtensionPlugins-targets.cmake")
  include("${CMAKE_CURRENT_LIST_DIR}/SMTKParaViewExtensionPlugins-paraview-plugin-properties.cmake")

  include("${CMAKE_CURRENT_LIST_DIR}/SMTKParaViewPlugins-smtk_paraview_plugins-targets-depends.cmake")
  include("${CMAKE_CURRENT_LIST_DIR}/SMTKParaViewPlugins-targets.cmake")
  include("${CMAKE_CURRENT_LIST_DIR}/SMTKParaViewPlugins-paraview-plugin-properties.cmake")
endif ()

if (SMTK_ENABLE_REMUS_SUPPORT)
  find_package(Remus ${_smtk_find_quietly})
  if (NOT Remus_FOUND)
    list(APPEND "${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE"
      "Remus dependency not found")
    set("${CMAKE_FIND_PACKAGE_NAME}_FOUND" 0)
  endif ()
endif ()

if (SMTK_ENABLE_PYTHON_WRAPPING)
  find_package(Python3 ${_smtk_find_quietly}
    COMPONENTS Development Interpreter)
  if (NOT Python3_FOUND)
    list(APPEND "${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE"
      "Python3 dependency not found")
    set("${CMAKE_FIND_PACKAGE_NAME}_FOUND" 0)
  endif ()

  # Set the interpreter up before `pybind11` uses the old Python modules to
  # find a different Python than we actually want.
  set(PYTHON_EXECUTABLE "${Python3_EXECUTABLE}")

  find_package(pybind11 ${_smtk_find_quietly})
  if (NOT pybind11_FOUND)
    list(APPEND "${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE"
      "pybind11 dependency not found")
    set("${CMAKE_FIND_PACKAGE_NAME}_FOUND" 0)
  endif ()
  set(SMTK_PYTHONPATH "@SMTK_PYTHON_MODULEDIR@")
endif ()

unset(_smtk_find_quietly)

set(CMAKE_PREFIX_PATH "${${CMAKE_FIND_PACKAGE_NAME}_CMAKE_PREFIX_PATH_save}")
unset("${CMAKE_FIND_PACKAGE_NAME}_CMAKE_PREFIX_PATH_save")

if (NOT DEFINED "${CMAKE_FIND_PACKAGE_NAME}_FOUND")
  set("${CMAKE_FIND_PACKAGE_NAME}_FOUND" 1)
endif ()
